<script type="text/javascript" class="source below">
// Note method 2) and 3) use `one`, this is because if `refresh` is called those events are triggered
$(function () {
	$("#demo2")
		.jstree({ "plugins" : ["themes","html_data","ui"] 
        })
		// 1) the loaded event fires as soon as data is parsed and inserted
		.bind("loaded.jstree", function (event, data) {})
		// 2) but if you are using the cookie plugin or the core `initially_open` option:
		.one("reopen.jstree", function (event, data) { })
		// 3) but if you are using the cookie plugin or the UI `initially_select` option:
		.one("reselect.jstree", function (event, data) { })
        
                .bind("select_node.jstree", function (event, data) { 
            
                });

});

	$(document).ready(function(){	
		//default usage
		//$("#news_form_metaDescription").charCount();
		//custom usage
		$("#news_extra_form_metaDescription").charCount({
			allowed: 70,		
			warning: 20,
			counterText: 'Characters left: '	
		});
                $("#news_extra_form_content").charCount({
			allowed: 200,		
			warning: 50,
			counterText: 'Characters left: '	
		});

	});
    
</script>
<script type="text/javascript" src="{{ asset('bundles/news/js/nicEdit-latest.js') }}"></script>
  <div class="title"><h5>Tables examples</h5></div>
  {% if status_form==1 %}
	 <div class="nNote nInformation hideit">
                <p><strong>SUCCESS: </strong> Content original has been created. You can see the post in this url here: <a href="{{ path('blog_show', {'slug': url1}) }}" target="_blank">{{url1}}</a></p>
         </div>
	
	{% elseif status_form==2 %}
	<div class="nNote nFailure hideit">
		<p><strong>FAILURE: </strong>Oops sorry. Something went wrong, try again.</p>
	</div>  
         {% elseif status_form==3 %}
	<div class="nNote nSuccess hideit">
		<p><strong>SUCCESS: </strong> Content translated has been created.</p>
	</div>
	 {% endif %}
   {{ form_start(form, {'attr': {'class': 'mainForm ui-formwizard', 'id': 'wizForm'}}) }}
     <div class="widget">   
      <div class="head"></div>
    <fieldset class="step ui-formwizard-content" id="first" style="display: block;">
        <h5> Create content  </h5>

           <div class="rowElem">
           <label>Title<span class="req">*</span></label>
           <div class="formRight">{{ form_widget(form.title) }}</div>
           <div class="formRight">{{ form_errors(form.title) }}</div>
           <div class="fix"></div>
           </div> 
           <div class="rowElem">
           <label>Title SEO<span class="req">*</span></label>  
           <div class="formRight">{{ form_widget(form.titleSeo) }}</div>
           <div class="formRight">{{ form_errors(form.titleSeo) }}</div>
           <div class="fix"></div>
           </div> 
           <div class="rowElem">
           <label>Meta Description</label>
           <div class="formRight">{{ form_widget(form.metaDescription) }}</div>
           <div class="formRight">{{ form_errors(form.metaDescription) }}</div>
           <div class="fix"></div>
           </div> 
           <div class="rowElem">
           {%if idNew ==0 %}
           <div class="nNote nWarning hideit" ><p><strong>WARNING: </strong>We've missing something, please select the first post related to this article.</p></div>                        
           {%endif%}
           {{ form_widget(form.content) }}
           {{ form_errors(form.content) }}

           </div>	
    </fieldset>
    <fieldset class="step ui-formwizard-content" id="second" style="display: none;">
           
           <div class="rowElem">
           <label>Language: <span class="req">*</span></label>
           <div class="formRight">
                English
           </div>
           <div class="fix"></div>
           </div>
           <div class="rowElem">
           <label>Status: <span class="req">*</span></label>
           <div class="formRight">
            {{ form_widget(form.status) }}
            {{ form_errors(form.status) }}
            </div>
            </div>
            <div class="rowElem">
            <input type="hidden" id="author" name="author" value="{{app.user.id}}">
            <input type="hidden" id="idNew" name="idNew" class="validate[required,maxSize[250]]" value="{{idNew}}">
           {%if idNew ==0 %}<div class="nNote nWarning hideit" ><p><strong>WARNING: </strong>We've missing something, please select the first post related to this article.</p></div>{%endif%}
            </div>
    </fieldset>
        <div class="wizNav"> 							
                <input class="basicBtn ui-wizard-content ui-formwizard-button" id="back" value="Back" type="reset" disabled="disabled">
                <input class="blueBtn ui-wizard-content ui-formwizard-button" id="next" value="Next" type="submit" {%if idNew ==0 %}disabled="disabled"{%endif%}>
        </div>
        </div>
		<!--	  </form>-->
              {{ form_end(form) }} 
<script>
$('#news_form_content').wysihtml5();
$( "#wizForm" ).submit(function( event ) {
if($("#idNew").val()!=="0"){

 var action= '{{ path('em_news_2edit', {'idNew':'data'}) }}';
 action=action.replace('data',$("#idNew").val())
 var datos = $(this).serialize();     
 console.log(action);  
 $.ajax({type: 'POST', url:action, script:true, cache:true,data: datos,
                   // beforeSend: function(response){ $('#formcontent').html('<div align="center"><img src="{{asset('bundles/news/images/loaders/loader8.gif')}}" alt="" class="p12"><br>Loading data...</div>');},
                    error: function(response){console.log(response);},
                    success: function(response) {
			if (response === "false"){
                            console.log(response);
			}else{
                        console.log(response);
                        $('#formcontent').html(response);
                        
			}
         }});
      //  return false;
  
}
 return false;
 
});

$( "#news_form_title" ).focusout(function() {
  //  $( "#news_form_slug" ).val( "focusout fired:" );
  var slug=this.value;
  console.log(slug);
  $( "#news_form_titleSeo" ).val(slug);
  });

</script>
